<template>
  <div class="list-page-container custom-ant">
    <a-card>
      <a-form layout="inline" @keyup.enter.native="handleSearch">
        <a-row :gutter="24">
          <a-col :md="6" :sm="24">
            <CompositeSearch
              :fieldList="fieldList"
              @getParams="getSearchValue"
              @adSearch="onAdSearch"
              @adClear="onAdClear"
              @tagClick="onTagClick">
              <template v-slot:ad-search-content>
                <a-form-model
                  ref="adSearchFormRef"
                  :model="adSearchFormData"
                  layout="vertical">
                  <a-row :gutter="24">
                    <a-col :span="24">
                      <a-form-model-item label="供应商状态">
                        <ASelectList
                          v-model="adSearchFormData.supplierStatus"
                          :isHasDict="false"
                          :defaultOption="supplierStatusOption"
                          placeholder="请选择供应商状态" />
                      </a-form-model-item>
                    </a-col>
                  </a-row>
                  <a-row :gutter="24">
                    <a-col :span="24">
                      <a-form-model-item label="待评估">
                        <ASelectList v-model="adSearchFormData.evaluateStatus" :isHasDict="false" :defaultOption="evaluateStatusOption"/>
                      </a-form-model-item>
                    </a-col>
                  </a-row>
                  <a-row :gutter="24">
                    <a-col :span="24">
                      <a-form-model-item label="创建类型">
                        <ASelectList v-model="adSearchFormData.createType" :isHasDict="false" :defaultOption="createTypeOption"/>
                      </a-form-model-item>
                    </a-col>
                  </a-row>
                  <a-row :gutter="24">
                    <a-col :span="24">
                      <a-form-model-item label="创建时间">
                        <a-range-picker
                          v-model="createTime"
                          format="YYYY-MM-DD"
                          style="width:100%;"
                          @change="(timeRange, timeStringRange) => setTimeRange('createTimeStart', 'createTimeEnd', timeRange, timeStringRange)"/>
                      </a-form-model-item>
                    </a-col>
                  </a-row>
                </a-form-model>
              </template>
            </CompositeSearch>
          </a-col>
          <a-col :md="18" :sm="24">
            <div class="space-btn">
              <a-button type="primary" icon="plus" @click="onAdd">添加</a-button>
              <a-button @click="onExport">导出</a-button>
              <a-button @click="onImport">导入</a-button>
              <a-button type="danger" @click="onBatchDelete">批量删除</a-button>
            </div>
          </a-col>
        </a-row>
      </a-form>
      <a-tabs type="card" v-model="curTabValue" @change="tabChange">
        <a-tab-pane v-for="item in tabList" :key="item.key">
          <span slot="tab">
            {{ `${item.tab}` }}
            <span v-if="item.toDone">{{ `(${item.toDone})` }}</span>
            <!-- <span v-if="['2', '4'].includes(item.key) && item.toDone">{{ `（${item.toDone}）` }}</span>
            <a-badge v-if="['1', '3'].includes(item.key)" :count="item.toDone" :offset="[0, -15]" /> -->
          </span>
        </a-tab-pane>
      </a-tabs>
      <a-table
        ref="table"
        rowKey="id"
        size="middle"
        bordered
        :loading="loading"
        :columns="columns"
        :dataSource="dataSource"
        :row-selection="{ fixed: true, selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        :scroll="{ x: '100%', autoHeight: true }"
        :pagination="pagination">
        <span slot="date" slot-scope="text">{{ text | DateFormat }}</span>
        <template slot="supplierStatus" slot-scope="text"><span>{{ supplierStatusEnum[text] || '' }}</span></template>
        <template slot="evaluateStatus" slot-scope="text"><span>{{ evaluateStatusEnum[text] || '' }}</span></template>
        <template slot="createType" slot-scope="text"><span>{{ createTypeEnum[text] || '' }}</span></template>
        <template slot="action" slot-scope="text, record">
          <span v-show="['1', '2'].includes(record.evaluateStatus)" class="cus-text" pointer>直接准入</span>
          <span v-show="['1', '2'].includes(record.evaluateStatus)" class="cus-text" pointer @click="onEvaluate(record)">
            <span v-show="record.evaluateStatus === '1'">提交评估</span>
            <span v-show="record.evaluateStatus === '2'">重新评估</span>
          </span>
          <span v-show="record.evaluateStatus === '3'" class="cus-text" pointer @click="onCheckStatement(record)">查看报表</span>
          <span v-show="['1', '2'].includes(record.supplierStatus)" class="cus-text" pointer danger @click="onDelete(record)">删除</span>
        </template>
      </a-table>
    </a-card>

    <!-- 供应商注册信息 -->
    <SupplierRegisterInfo ref="SupplierRegisterInfo" @successCallback="handleSearch" />
    <!-- 智能估计看板 -->
    <IntelligentEstimationBoard ref="IntelligentEstimationBoard" />
  </div>
</template>

<script>
import ListPageMixin from '@/mixins/ListPageMixin.js';
import optionsMixin from '@views/supplier-manage/register/optionsMixin.js'
import SupplierRegisterInfo from '@views/supplier-manage/register/components/SupplierRegisterInfo.vue'
import IntelligentEstimationBoard from '@views/supplier-manage/register/components/IntelligentEstimationBoard.vue'

export default {
  name: 'RegisterIndex',
  mixins: [ ListPageMixin, optionsMixin ],
  components: {
    SupplierRegisterInfo,
    IntelligentEstimationBoard
  },
  data() {
    return {
      adSearchFormData: {
        supplierStatus: '',
        evaluateStatus: '',
        createType: '',
        createTimeStart: '',
        createTimeEnd: '',
      },
      createTime: [],
      curTabValue: '0',
      tabList: [
        { tab: '全部', key: '0' , toDone: 4 },
        { tab: '潜在供应商', key: '1', toDone: 2 },
        { tab: '准入供应商', key: '2', toDone: 1 },
        { tab: '淘汰供应商', key: '3', toDone: 1 },
      ],
      dataSource: [],
      originalDataSource: [
        {
          supplierStatus: '1',
          evaluateStatus: '1',
          uscCode: '91411628MA442QNF9U',
          supplierFullName: '河南盛世机械工具集团有限公司',
          businessScope: '土石方工程、拆除工程;建筑机械设备销售、租赁、',
          contactAddress: '广州市黄埔区黄埔东路1号',
          legalRepresentative: '杨先生',
          contactPhone: '13800138000',
          InquiryChannel: '企查查',
          depositBank: '工商银行',
          receivablesAccount: '6212263602053303588',
          payee: '杨先生',
          createType: '1',
          createPerson: '杨先生',
          createTime: '2025-1-10 12:00:00',
          updateTime: '2025-1-10 12:00:00',
        },
        {
          supplierStatus: '1',
          evaluateStatus: '2',
          uscCode: '91411628MA442QNF9U',
          supplierFullName: '广州三五零配件有限公司',
          businessScope: '土石方工程、拆除工程;建筑机械设备销售、租赁、',
          contactAddress: '广州市黄埔区黄埔东路1号',
          legalRepresentative: '杨先生',
          contactPhone: '13800138000',
          InquiryChannel: '企查查',
          depositBank: '工商银行',
          receivablesAccount: '6212263602053303588',
          payee: '杨先生',
          createType: '1',
          createPerson: '杨先生',
          createTime: '2025-1-10 12:00:00',
          updateTime: '2025-1-10 12:00:00',
        },
        {
          supplierStatus: '2',
          evaluateStatus: '3',
          uscCode: '91411628MA442QNF9U',
          supplierFullName: '广汽集团广天有限公司',
          businessScope: '土石方工程、拆除工程;建筑机械设备销售、租赁、',
          contactAddress: '广州市黄埔区黄埔东路1号',
          legalRepresentative: '杨先生',
          contactPhone: '13800138000',
          InquiryChannel: '企查查',
          depositBank: '工商银行',
          receivablesAccount: '6212263602053303588',
          payee: '杨先生',
          createType: '1',
          createPerson: '杨先生',
          createTime: '2025-1-10 12:00:00',
          updateTime: '2025-1-10 12:00:00',
        },
        {
          supplierStatus: '3',
          evaluateStatus: '3',
          uscCode: '91411628MA442QNF9U',
          supplierFullName: '河南盛世机械工具集团有限公司',
          businessScope: '土石方工程、拆除工程;建筑机械设备销售、租赁、',
          contactAddress: '广州市黄埔区黄埔东路1号',
          legalRepresentative: '杨先生',
          contactPhone: '13800138000',
          InquiryChannel: '企查查',
          depositBank: '工商银行',
          receivablesAccount: '6212263602053303588',
          payee: '杨先生',
          createType: '1',
          createPerson: '杨先生',
          createTime: '2025-1-10 12:00:00',
          updateTime: '2025-1-10 12:00:00',
        }
      ]
    }
  },
  created() {
    this.handleSearch();
  },
  methods: {
    // 获取 搜索框参数
    getSearchValue(currentValue, selectFiledList) {
      console.log(currentValue, selectFiledList, 'getSearchValue');
      this.handleSearch();
    },
    // 确定搜索 高级搜索
    onAdSearch() {
      console.log(this.adSearchFormData, '确定搜索 高级搜索');
      this.handleSearch();
    },
    // 重置 高级搜索
    onAdClear() {
      console.log('重置 高级搜索');
    },
    onTagClick(data) {
      console.log(data, 'onTagClick');
      const { name } = data;
      if (['筛选组合01', '筛选组合02', '筛选组合03'].includes(name)) {
        this.adSearchFormData.supplierStatus = '1';
        this.adSearchFormData.evaluateStatus = '1';
        this.adSearchFormData.createType = '1';
      } else if (['筛选组合04', '筛选组合05', '筛选组合06'].includes(name)) {
        this.adSearchFormData.supplierStatus = '2';
        this.adSearchFormData.evaluateStatus = '2';
        this.adSearchFormData.createType = '2';
      } else {
        this.adSearchFormData.supplierStatus = '3';
        this.adSearchFormData.evaluateStatus = '3';
        this.adSearchFormData.createType = '3';
      }
    },
    handleSearch() {
      this.loading = true;
      setTimeout(() => {
        this.loading = false;
        this.onSelectClear();
        if (this.curTabValue === '0') {
          this.dataSource = this.originalDataSource
        } else {
          this.dataSource = this.originalDataSource.filter(item => item.supplierStatus === this.curTabValue);
        }
      }, 100)
    },
    // 添加
    onAdd() {
      this.$refs.SupplierRegisterInfo.onDrawerOpen();
    },
    // 导出
    onExport() {

    },
    // 导入
    onImport() {

    },
    // 删除
    onBatchDelete() {
      console.log(this.selectedRowKeys, this.selectedRows, 'onBatchDelete');
      if (this.selectedRowKeys.length) {
        this.$confirm({
          title: '批量删除',
          content: '确认批量删除？',
          okText: '确认',
          cancelText: '取消',
          onOk: () => {
            this.handleSearch();
            this.$message.success(`操作成功`);
          }
        });
      } else {
        this.$message.error(`请选择数据！`);
      }
    },
    tabChange() {
      this.handleSearch();
    },
    // 范围日期处理
    setTimeRange(startTimeName, endTimeName, timeRange, timeStringRange) {
      if (timeStringRange.length > 0) {
        const [one, two] = timeStringRange;
        this.adSearchFormData[startTimeName] = one + ' ' + '00:00:00';
        this.adSearchFormData[endTimeName] = two + ' ' + '23:59:59';
      } else {
        this.adSearchFormData[startTimeName] = '';
        this.adSearchFormData[endTimeName] = '';
      }
    },
    onEvaluate(record) {
      this.$refs.SupplierRegisterInfo.onDrawerOpen();
    },
    onCheckStatement(record) {
      this.$refs.IntelligentEstimationBoard.onDialogOpen();
    },
    onDelete(record) {
      this.$confirm({
        title: '删除',
        content: '确认删除？',
        okText: '确认',
        cancelText: '取消',
        onOk: () => {
          this.handleSearch();
          this.$message.success(`操作成功`);
        }
      });
    }
  }
}
</script>

<style lang="less" scoped>
</style>
